package com.autumn.security.context;

import org.apache.shiro.SecurityUtils;

import com.autumn.runtime.session.claims.DefaultIdentityClaims;
import com.autumn.runtime.session.claims.IdentityClaims;
import com.autumn.security.user.IAutumnUser;

/**
 * 安全上下文
 * 
 * @author 老码农
 *
 *         2018-04-09 16:27:10
 */
public class AutumnSecurityContextHolder {

	/**
	 * 获取用户
	 * 
	 * @return
	 *
	 */
	public static IAutumnUser getAutumnUser() {
		Object principal = SecurityUtils.getSubject().getPrincipal();
		if (principal != null && principal instanceof IAutumnUser) {
			return (IAutumnUser) principal;
		}
		return null;
	}

	/**
	 * 获取声明集合
	 * 
	 * @return
	 *
	 */
	public static IdentityClaims getIdentityClaims() {
		IAutumnUser user = getAutumnUser();
		if (user != null && user.getIdentityClaims() != null) {
			return user.getIdentityClaims();
		}
		return DefaultIdentityClaims.DEFAULT_IDENTITY_CLAIMS;
	}

}
